﻿using UnityEngine;
using System.Collections;
using Dict.Blo;
using Dict.DataModel;
using ProtoBuf.Message;

namespace UI
{
    public class UIFishItem
    {
        public TableFishSkill fishData;

        public long num;


        public UIFishItem(TableFishSkill data)
        {
            fishData = data;
            num = 0;
        }

        public void InitData(SimpleItem data)
        {
            fishData = DictFishBlo.GetFishSkillTable(data.id);
            num = data.num;
        }

        public int GetCanMakeNum()
        {
            if(fishData.Type != FishItemType.DISH)
            {
                return 0;
            }

            long minNum = -1;
            string[] needs = fishData.Material.Split(';');
            for(int i = 0; i < needs.Length; i++)
            {
                string[] info = needs[i].Split(',');
                if(info[0].StartsWith(Dict.Config.TableConst.FishItem))
                {
                    long num = StaticData.playerData.GetFishItemCount(info[0])/int.Parse(info[1]);
                    if(minNum == -1 || num < minNum)
                    {
                        minNum = num;
                    }
                }
                else if(info[0] == Dict.Config.TableConst.coin)
                {
                    long num = StaticData.playerData.coin / int.Parse(info[1]);
                    if (minNum == -1 || num < minNum)
                    {
                        minNum = num;
                    }
                }
            }

            return (int)minNum;
        }

        public string GetFishItemDesc()
        {
            if(fishData.Type != FishItemType.DISH)
            {
                return TableTextBlo.GetText("desc_" + fishData.FishItemID);
            }
            string desc = "";
            if(fishData.ValueType == "onetimeRecover")
            {
                desc = string.Format(TableTextBlo.GetText("wild_recover_eff"), fishData.Value);
            }
            else if (fishData.ValueType.StartsWith("permanent"))
            {
                desc = TableTextBlo.GetText("permanent_add") + GetAmountWord(fishData.Quality) + GetPropsString();
            }
            else if (fishData.ValueType.StartsWith("extra"))
            {
                string[] values = fishData.Value.Split(';');
                string addname = "";
                if (fishData.ValueType == "extraExp")
                    addname = TableTextBlo.GetText("exp");
                else if (fishData.ValueType == "extraCoin")
                    addname = TableTextBlo.GetText("coin");
                else if (fishData.ValueType == "extraCoinExp")
                    addname = TableTextBlo.GetText("exp_and_coin");
                addname += "+" + values[1] + "%";
                desc = string.Format(TableTextBlo.GetText("copy_expcoin_add_eff"), values[0], addname, Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.LifeSkillFightTenTimeCost);
            }
            return desc;
        }

        string GetAmountWord(int quality)
        {
            switch(quality)
            {
                case 1:
                case 2:
                    {
                        return TableTextBlo.GetText("a_small_amount");
                    }
                case 3:
                case 4:
                    {
                        return TableTextBlo.GetText("a_spot_amount");
                    }
                default:
                    {
                        return TableTextBlo.GetText("a_large_amount");
                    }
            }
        }

        string GetPropsString()
        {
            string propstr = "";
            string[] props = fishData.Value.Split(';');
            for(int i = 0; i < props.Length; i++)
            {
                if (propstr != "")
                    propstr += "、";
                propstr += TableTextBlo.GetText("word_" + props[i]);
            }
            return propstr;
        }

        public string Get2dTexturePath()
        {
            return "fish2d/" + fishData.FishItemID.Replace("Item","_png");
        }
    }
}

